

class ListenerScroll {
    constructor() {
        this.events = [] 
    }

    add(event,fn,wait) {
        if(this.events.indexOf(event)) {
            return;
        }
        this.events.push(event);
        let debounce = this.setdebounce(fn,wait);
        window.addEventListener(event,debounce);
    }
    
    setdebounce(fn,wait) {
        var timer = null;
        return function() {
            if(timer !== null) {
                clearTimeout(timer);
            }
            timer = setTimeout(fn,wait);
        }
    }
}

module.exports = ListenerScroll;